package com.ruoyi.voucher.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.voucher.domain.VoucherAccessory;
import com.ruoyi.voucher.service.IVoucherAccessoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 凭证附件Controller
 * 
 * @author ruoyi
 * @date 2025-02-21
 */
@RestController
@RequestMapping("/voucherAccessory")
public class VoucherAccessoryController extends BaseController
{
    @Autowired
    private IVoucherAccessoryService voucherAccessoryService;

    /**
     * 查询凭证附件列表
     */
    @RequiresPermissions("voucher:voucherAccessory:list")
    @GetMapping("/list")
    public TableDataInfo list(VoucherAccessory voucherAccessory)
    {
        startPage();
        List<VoucherAccessory> list = voucherAccessoryService.selectVoucherAccessoryList(voucherAccessory);
        return getDataTable(list);
    }

    /**
     * 导出凭证附件列表
     */
    @RequiresPermissions("voucher:voucherAccessory:export")
    @Log(title = "凭证附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VoucherAccessory voucherAccessory)
    {
        List<VoucherAccessory> list = voucherAccessoryService.selectVoucherAccessoryList(voucherAccessory);
        ExcelUtil<VoucherAccessory> util = new ExcelUtil<VoucherAccessory>(VoucherAccessory.class);
        util.exportExcel(response, list, "凭证附件数据");
    }

    /**
     * 获取凭证附件详细信息
     */
    @RequiresPermissions("voucher:voucherAccessory:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(voucherAccessoryService.selectVoucherAccessoryById(id));
    }

    /**
     * 新增凭证附件
     */
    @RequiresPermissions("voucher:voucherAccessory:add")
    @Log(title = "凭证附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoucherAccessory voucherAccessory)
    {
        return toAjax(voucherAccessoryService.insertVoucherAccessory(voucherAccessory));
    }

    /**
     * 修改凭证附件
     */
    @RequiresPermissions("voucher:voucherAccessory:edit")
    @Log(title = "凭证附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoucherAccessory voucherAccessory)
    {
        return toAjax(voucherAccessoryService.updateVoucherAccessory(voucherAccessory));
    }

    /**
     * 删除凭证附件
     */
    @RequiresPermissions("voucher:voucherAccessory:remove")
    @Log(title = "凭证附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(voucherAccessoryService.deleteVoucherAccessoryByIds(ids));
    }
}
